home *** CD-ROM | disk | FTP | other *** search
/ Megaware 1 / Megaware Volume 1.iso / programg / c-tutor / message.cpp < prev    next >
Text File  |  1990-07-20  |  1KB  |  52 lines

  1.                                    // Chapter 1 - Program 3
  2. #include "iostream.h"
  3. #include "string.h"
  4.  
  5. main()
  6. {
  7. int index;
  8. float distance;
  9. char letter;
  10. char name[25];
  11.  
  12.    index = -23;
  13.    distance = 12.345;
  14.    letter = 'X';
  15.    strcpy(name,"John Doe");
  16.  
  17.    cout << "The value of index is "    << index    << "\n";
  18.    cout << "The value of distance is " << distance << "\n";
  19.    cout << "The value of letter is "   << letter   << "\n";
  20.    cout << "The value of name is "     << name     << "\n";
  21.  
  22.    index = 31;
  23.    cout << "The decimal value of index is " << dec << index << "\n";
  24.    cout << "The octal value of index is " << oct << index << "\n";
  25.    cout << "The hex value of index is " << hex << index << "\n";
  26.    cout << "The character letter is " << (char)letter << "\n";
  27.    cout << "The value of distance is " << form("%12.4f\n",distance);
  28.    cout << form("Hello world!") << "\n";
  29.  
  30.    cout << "Input a decimal value --> ";
  31.    cin  >> index;
  32.    cout << "The hex value of the input is " << index << "\n";
  33. }
  34.  
  35.  
  36.  
  37.  
  38. // Result of execution
  39. //
  40. // The value of index is -23
  41. // The value of distance is 12.345
  42. // The value of letter is X
  43. // The value of name is John Doe
  44. // The decimal value of index is   31
  45. // The octal value of index is   37
  46. // The hex value of index is   1f
  47. // The character letter is X
  48. // The value of distance is      12.3450
  49. // Hello world!
  50. // Input a decimal value --> 999
  51. // The hex value of the input is 3e7
  52.